package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistbj;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistbj.vo.DpWestListBjPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistbj.vo.DpWestListBjRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistbj.vo.DpWestListBjSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpWestListBjDO;
import cn.iocoder.yudao.module.erp.service.dpwest.DpWestListBjService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 北疆口岸仓西线清单")
@RestController
@RequestMapping("/erp/dp-west-list-bj")
@Validated
public class DpWestListBjController {

    @Resource
    private DpWestListBjService dpWestListBjService;

    @PostMapping("/create")
    @Operation(summary = "创建北疆口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:create')")
    public CommonResult<Long> createDpWestListBj(@Valid @RequestBody DpWestListBjSaveReqVO createReqVO) {
        return success(dpWestListBjService.createDpWestListBj(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新北疆口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:update')")
    public CommonResult<Boolean> updateDpWestListBj(@Valid @RequestBody DpWestListBjSaveReqVO updateReqVO) {
        dpWestListBjService.updateDpWestListBj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除北疆口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:delete')")
    public CommonResult<Boolean> deleteDpWestListBj(@RequestParam("id") Long id) {
        dpWestListBjService.deleteDpWestListBj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得北疆口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:query')")
    public CommonResult<DpWestListBjRespVO> getDpWestListBj(@RequestParam("id") Long id) {
        DpWestListBjDO dpWestListBj = dpWestListBjService.getDpWestListBj(id);
        return success(BeanUtils.toBean(dpWestListBj, DpWestListBjRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得北疆口岸仓西线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:query')")
    public CommonResult<PageResult<DpWestListBjRespVO>> getDpWestListBjPage(@Valid DpWestListBjPageReqVO pageReqVO) {
        PageResult<DpWestListBjDO> pageResult = dpWestListBjService.getDpWestListBjPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpWestListBjRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出北疆口岸仓西线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-bj:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpWestListBjExcel(@Valid DpWestListBjPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpWestListBjDO> list = dpWestListBjService.getDpWestListBjPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "北疆口岸仓西线清单.xls", "数据", DpWestListBjRespVO.class,
                        BeanUtils.toBean(list, DpWestListBjRespVO.class));
    }

}